<template>
	<div class="game-container report-container">
		<div class="view-container dealer-container">
			<div class="params">
				<el-form
					ref="form"
					:inline="true"
					:model="queryData"
					label-width="auto"
				>
					<el-form-item :label="`${$t('common.belong_merchant')}:`">
						<merchant-select
							v-model="queryData.merchantId"
							:merchantInfo.sync="merchantObj"
						></merchant-select>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.payment_time'
							)}:`
						"
					>
						<el-date-picker
							v-model="searchTime"
							size="medium"
							:picker-options="pickerOptions"
							format="yyyy-MM-dd HH:mm:ss"
							type="datetimerange"
							range-separator="-"
							:start-placeholder="$t('common.start_date')"
							:end-placeholder="$t('common.end_date')"
							align="right"
							:clearable="false"
							:default-time="defaultTime"
						></el-date-picker>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.commission_month'
							)}:`
						"
					>
						<el-date-picker
							v-model="transMonth"
							size="medium"
							format="yyyy-MM"
							type="month"
							align="right"
						></el-date-picker>
					</el-form-item>
					<el-form-item :label="`${$t('funds.order_no')}:`">
						<el-input
							v-model="queryData.orderNo"
							clearable
							size="medium"
							:placeholder="$t('common.please_enter')"
							:disabled="loading"
							@keyup.enter.native="enterSearch"
						></el-input>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.trans_out_proxy_name'
							)}:`
						"
					>
						<el-input
							v-model="queryData.transOutProxyName"
							clearable
							size="medium"
							:placeholder="$t('common.please_enter')"
							:disabled="loading"
							@keyup.enter.native="enterSearch"
						></el-input>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.proxy_level_name'
							)}:`
						"
						class="tagheight"
					>
						<el-select
							v-model="queryData.transOutProxyLevelId"
							clearable
							:placeholder="$t('common.select_all')"
							:popper-append-to-body="false"
						>
							<el-option
								v-for="item in proxyLevelArr"
								:key="item.id"
								:label="item.id"
								:value="item.id"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.trans_in_proxy_name'
							)}:`
						"
					>
						<el-input
							v-model="queryData.transInProxyName"
							clearable
							size="medium"
							:placeholder="$t('common.please_enter')"
							:disabled="loading"
							@keyup.enter.native="enterSearch"
						></el-input>
					</el-form-item>
					<el-form-item>
						<el-button
							type="primary"
							icon="el-icon-search"
							size="medium"
							@click="search"
						>
							{{ $t('common.search') }}
						</el-button>
						<el-button
							icon="el-icon-refresh-left"
							:disabled="loading"
							size="medium"
							@click="reset"
						>
							{{ $t('common.reset') }}
						</el-button>
						<el-button
							v-if="hasPermission('405071')"
							icon="el-icon-download"
							type="warning"
							:disabled="loading"
							size="medium"
							@click="handleExportExcel"
						>
							{{ $t('common.export') }}
						</el-button>
					</el-form-item>
				</el-form>
			</div>
			<div class="content">
				<el-table
					ref="tables"
					v-loading="loading"
					border
					size="mini"
					show-summary
					:data="tableData"
					style="width: 100%"
					class="small-size-table"
					:header-cell-style="getRowClass"
					element-loading-spinner="el-icon-loading"
					:summary-method="(val) => handleRow(val, subSummary)"
				>
					<el-table-column
						prop="orderNo"
						min-width="300"
						align="center"
						:label="$t('funds.order_no')"
					>
						<template slot-scope="scope">
							<Copy :title="scope.row.orderNo" :copy="copy">
								{{ scope.row.orderNo }}
							</Copy>
						</template>
					</el-table-column>

					<el-table-column
						prop="transMonth"
						align="center"
						:label="
							$t(
								'funds.proxy_member_funds_record.commission_month'
							)
						"
					></el-table-column>
					<el-table-column
						prop="transOutProxyName"
						align="center"
						:label="
							$t(
								'funds.proxy_member_funds_record.trans_out_proxy_name'
							)
						"
					>
						<template slot-scope="scope">
							<Copy
								v-if="scope.row.transOutProxyName"
								:title="scope.row.transOutProxyName"
								:copy="copy"
							>
								{{ scope.row.transOutProxyName }}
							</Copy>
							<span v-else>-</span>
						</template>
					</el-table-column>
					<el-table-column
						prop="merchantName"
						align="center"
						:label="$t('common.belong_merchant')"
					>
						<template slot-scope="scope">
							{{ scope.row.merchantName || '-' }}
						</template>
					</el-table-column>
					<el-table-column
						prop="transOutProxyLevelId"
						align="center"
						:label="
							$t(
								'funds.proxy_member_funds_record.proxy_level_name'
							)
						"
					>
						<template slot-scope="scope">
							{{ scope.row.transOutProxyLevelId }}
						</template>
					</el-table-column>
					<el-table-column
						prop="transAmount"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.trans_amount')
						"
					>
						<template slot-scope="scope">
							{{ handleCurrency(scope.row.currency) }}
							{{
								handleNumber(
									scope.row.currency,
									scope.row.transAmount
								)
							}}
						</template>
					</el-table-column>
					<el-table-column
						prop="transDate"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.payment_time')
						"
					></el-table-column>
					<el-table-column
						prop="transInProxyName"
						align="center"
						:label="
							$t(
								'funds.proxy_member_funds_record.trans_in_proxy_name'
							)
						"
					>
						<template slot-scope="scope">
							<Copy
								:title="scope.row.transInProxyName"
								:copy="copy"
							>
								{{ scope.row.transInProxyName }}
							</Copy>
						</template>
					</el-table-column>
				</el-table>
				<!-- 分页 -->
				<el-pagination
					:current-page.sync="pageNum"
					class="pageValue"
					background
					layout="total, sizes,prev, pager, next, jumper"
					:page-size="pageSize"
					:page-sizes="pageSizes"
					:total="total"
					@current-change="handleCurrentChange"
					@size-change="handleSizeChange"
				></el-pagination>
			</div>
		</div>
	</div>
</template>

<script>
// 新版代理转账记录、需要结合原型调整
import list from '@/mixins/list'
import dayjs from 'dayjs'
import { routerNames } from '@/utils/consts'
import summaryList from './components/summaryList'
const end = dayjs().endOf('day')
const start = dayjs().startOf('day')
const startM = dayjs()
	.startOf('month')
	.subtract(1, 'month')
export default {
	name: routerNames.commissionPayment,
	mixins: [list, summaryList],
	data() {
		return {
			queryData: {},
			searchTime: [start, end],
			transMonth: startM,
			tableData: [],
			proxyLevelArr: [],
			subSummary: {},
			merchantObj: ''
		}
	},
	computed: {
		accessStatusType() {
			return this.globalDics.accessStatusType
		}
	},
	created() {
		this.getProxyLevelArr()
	},
	methods: {
		getProxyLevelArr() {
			this.$api.getProxylevelnameList().then((res) => {
				this.proxyLevelArr = res.data || []
			})
		},
		loadData() {
			this.loading = true
			const timeArr = this.searchTime || []
			const month = this.transMonth || ''
			const params = {
				...this.queryData,
				transMonth: month ? dayjs(month).format('YYYY-MM') : '',
				startTime: dayjs(timeArr[0]).format('YYYY-MM-DD HH:mm:ss'),
				endTime: dayjs(timeArr[1]).format('YYYY-MM-DD HH:mm:ss'),
				...this.getParams()
			}
			this.pageCurrency = this.merchantObj?.currency || ''
			this.$api
				.getProxyCommissionPaymentList(params)
				.then((res) => {
					const { record, totalRecord, summary } = res.data || {}
					this.tableData = record || []
					this.total = totalRecord || 0
					this.subSummary = summary || {}
					this.loading = false
				})
				.catch(() => {
					this.loading = false
				})
		},

		reset() {
			this.queryData = {}
			this.merchantObj = ''
			this.searchTime = [start, end]
			this.transMonth = startM
			this.pageNum = 1
			this.loadData()
		},
		handleExportExcel() {
			const timeArr = this.searchTime || []
			const month = this.transMonth || ''
			const params = {
				...this.queryData,
				transMonth: month ? dayjs(month).format('YYYY-MM') : '',
				startTime: dayjs(timeArr[0]).format('YYYY-MM-DD HH:mm:ss'),
				endTime: dayjs(timeArr[1]).format('YYYY-MM-DD HH:mm:ss')
			}
			this.exportExcel(params)
		}
	}
}
</script>

<style lang="scss" scoped>
::v-deep .el-table__fixed-footer-wrapper .cell,
::v-deep .el-table__footer-wrapper .cell {
	height: 100%;
	padding: 0 !important;
	margin: 0 !important;
	> div {
		height: 100%;
	}
}
::v-deep .footer_count_row {
	min-height: 50px;
	height: 50%;
	display: flex;
	font-weight: 700;
	padding: 5px 0;
	align-items: center;
	flex-direction: column;
	justify-content: center;
}
::v-deep .footer_count_row_border {
	border-top: 1px solid #ebeef5;
}
</style>
